package com.xjscrm.console.chat.frame.dto;

import com.alibaba.fastjson.JSON;
import com.uzai.mobile.collect.api.dto.trigger.talk.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 聊天记录(ChatTalkRecord)表DTO
 *
 * @author szl
 * @since 2024-03-12 14:49:38
 */
@Data
@ApiModel("聊天记录 DTO对象")
public class ChatRecordDTO {

    @ApiModelProperty("主键id")
    private Long id;

    @ApiModelProperty("聊天回话id")
    private Long talkSessionId;

    @ApiModelProperty("回话id/可以是好友微信id或群聊id")
    private String conversationId;

    @ApiModelProperty("头像")
    private String headImgUrl;

    @ApiModelProperty("发送人的微信id, 群聊时一般会有值")
    private String sendWxId;

    @ApiModelProperty("发送人的微信名称, 群聊时一般会有值")
    private String sendWxName;

    @ApiModelProperty("消息来源: 2020:客户发送,2021:客服发送")
    private Integer source;

    @ApiModelProperty("发送内容")
    private String content;

    @ApiModelProperty("发送时间")
    private Integer sendTime;

    @ApiModelProperty("微信/企微发送时间")
    private Integer wxSendTime;

    @ApiModelProperty("发送状态. 1010:发送中, 1011:发送成功, 1012:发送失败")
    private Integer sendStatus;

    @ApiModelProperty("消息id")
    private Long msgId;

    @ApiModelProperty("远程消息id")
    private Long remoteMsgId;

    @ApiModelProperty("创建时间")
    private Integer createTime;

    @ApiModelProperty("创建人")
    private Integer createBy;

    @ApiModelProperty("是否撤回, 0:未撤回, 1:撤回")
    private Integer recall;

    @ApiModelProperty(value = "聊天消息类型, 1:文本, 2:图片, 4:视频, 6:链接, 8:文件, 9:名片, 13:小程序, 14:表情, 25: 视频号")
    private Integer contentType;

    @ApiModelProperty(value = "文本消息")
    private MicaTalkContentTextMsg textContent;

    @ApiModelProperty(value = "图片/视频/emoji(企微可能会有不同)")
    private MicaTalkContentUrlMsg urlContent;

    @ApiModelProperty(value = "文件")
    private MicaTalkContentFileMsg fileContent;

    @ApiModelProperty(value = "链接消息")
    private MicaTalkContentLinkMsg linkContent;

    @ApiModelProperty(value = "小程序消息")
    private MicaTalkContentMiniprogramMsg miniprogramContent;

    @ApiModelProperty(value = "视频号消息")
    private MicaTalkContentSphMsg sphContent;

    @ApiModelProperty(value = "名片消息")
    private MicaTalkContentNameCardMsg nameCardContent;

    public void parse() {
        switch (contentType) {
            case 1:
                textContent = JSON.parseObject(content, MicaTalkContentTextMsg.class);
                break;
            case 2:
            case 4:
            case 14:
                urlContent = JSON.parseObject(content, MicaTalkContentUrlMsg.class);
                break;
            case 6:
                linkContent = JSON.parseObject(content, MicaTalkContentLinkMsg.class);
                break;
            case 8:
                fileContent = JSON.parseObject(content, MicaTalkContentFileMsg.class);
                break;
            case 9:
                nameCardContent = JSON.parseObject(content, MicaTalkContentNameCardMsg.class);
                break;
            case 13:
                miniprogramContent = JSON.parseObject(content, MicaTalkContentMiniprogramMsg.class);
                break;
            case 25:
                sphContent = JSON.parseObject(content, MicaTalkContentSphMsg.class);
                break;
        }
    }
}

